package com.ceshi.controller;

import com.ceshi.pojo.Dept;
import com.ceshi.pojo.Result;
import com.ceshi.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.logging.Logger;

@Slf4j
@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;

    // @RequestMapping(value = "/depts",method = RequestMethod.GET)
    @GetMapping("/depts")
    public Result list() {
        log.info ("查询全部数据");
        List<Dept> deptList = deptService.list ();
        return Result.success (deptList);

    }

    @DeleteMapping("/depts/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info ("根据id删除部门:{}", id);
        deptService.delete (id);
        return Result.success ();
    }

    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept) {
        log.info ("新增部门：{}", dept);
        deptService.add (dept);
        return Result.success ();
    }
}
